<include file="public/head"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>

</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:cmf_plugin_url('QbtAdvertising://AdminIndex/index')}">广告列表页面</a></li>
        <li class="active"><a href="#">添加广告页面</a></li>
    </ul>
    <form action="{:cmf_plugin_url('QbtAdvertising://AdminIndex/addpost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered">
                    <tr>
                        <th>广告名称<span style="color: red;">*</span></th>
                        <td>
                            <input class="form-control" type="text" name="ad_name"
                                   id="ad_name" required value="" placeholder="请输入广告名称"/>
                        </td>
                    </tr>
                    
                    <tr>
                        <th>广告位置</th>
                        <td>
                            <select class="form-control" name="position_id" onchange="showMedia(this.value)">
                                <option value="-1">请选择</option>
                                <?php
                                    if(count($lists)>0){
                                        foreach($lists as $val){
                                ?>
                                <option value="{$val['id']}">{$val['position_name']}</option>
                                <?php
                                        }
                                    }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tbody id="link" style="display:none">
                    <tr>
                        <th>广告链接</th>
                        <td>
                            <input class="form-control" type="text" name="ad_link"
                                   value="" placeholder="请输入广告链接">
                        </td>
                    </tr>

                    <tr>
                        <th>广告内容</th>
                        <td><textarea class="form-control" name="ad_text" style="height: 50px;"></textarea>
                        </td>
                    </tr>
                    </tbody>
                    <tbody id="1" style="display:none">
                    </tbody>
                    <tbody id="0" style="display:none">
                    <tr>
                        <th>缩略图</th>
                        <td>
                            <div style="text-align: center;">
                                <input type="hidden" name="ad_img" id="thumbnail" value="">
                                <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
                                    <img src="/qbtcmf/public/themes/admin_simpleboot3/public/assets/images/default-thumbnail.png"
                                         id="thumbnail-preview"
                                         width="135" style="cursor: pointer"/>
                                </a>
                                <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
                            </div>
                        </td>
                    </tr>
                    </tbody>
                    <tbody id="2" style="display:none">
                    <tr>
                        <th>自定义代码</th>
                        <td><textarea class="form-control" name="ad_code" style="height: 50px;"></textarea>
                        </td>
                    </tr>
                    </tbody>
                    
                    <tr>
                        <th>开始时间</th>
                        <td>
                            <input class="form-control js-bootstrap-datetime" type="text" name="start_time"
                                   value="{:date('Y-m-d H:i:s',time())}">
                        </td>
                    </tr>
                    <tr>
                        <th>结束时间</th>
                        <td>
                            <input class="form-control js-bootstrap-datetime" type="text" name="end_time"
                                   value="{:date('Y-m-d H:i:s',time())}">
                        </td>
                    </tr>
                    <tr>
                        <th>是否开启</th>
                        <td>
                            <select class="form-control" name="enabled">
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                        <!-- <a class="btn btn-default" href="{:url('AdminPage/index')}">{:lang('BACK')}</a> -->
                        <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<include file="public/scripts"/>
<script type="text/javascript">
$(function () {
    $('.btn-cancel-thumbnail').click(function () {
        $('#thumbnail-preview').attr('src', '/qbtcmf/public/themes/admin_simpleboot3/public/assets/images/default-thumbnail.png');
        $('#thumbnail').val('');
    });
});

var MediaList = new Array('0', '1', '2');
function showMedia(AdMediaType)
  {
    if(AdMediaType == -1){
        for (I = 0; I < MediaList.length; I ++){
            document.getElementById(MediaList[I]).style.display = "none";
        }
        document.getElementById("link").style.display = "none";
    }else{
        $.ajax({
            url:"{:cmf_plugin_url('QbtAdvertising://AdminIndex/lxajax')}", //用POST方式传输
            type:'post', //数据格式:JSON
            dataType:'json', //目标地址
            data:{
              id:AdMediaType
            },
            success:function(d){
                console.log(d);
                if(d == 2){
                    document.getElementById("link").style.display = "none";
                }else{
                    document.getElementById("link").style.display = "";
                }
                for (I = 0; I < MediaList.length; I ++)
                {
                  if (MediaList[I] == d)
                    document.getElementById(d).style.display = "";
                  else
                    document.getElementById(MediaList[I]).style.display = "none";
                }

            }
        })
    }
    

    
  }


</script>
</body>
</html>